package com.cndongtai.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.cndongtai.dao.BaseDao;
import com.cndongtai.dao.inter.UserRoleMapper;
import com.cndongtai.po.UserRole;

@Repository("userRoleDao")
public class UserRoleDao extends BaseDao implements UserRoleMapper {

	@Override
	public boolean addUserRole(UserRole userRole) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			UserRoleMapper operation = sqlSession.getMapper(UserRoleMapper.class);
			return operation.addUserRole(userRole);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public List<UserRole> queryUserRoleList(Long userId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			UserRoleMapper operation = sqlSession.getMapper(UserRoleMapper.class);
			return operation.queryUserRoleList(userId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public boolean deleteUserRole(Long userId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			UserRoleMapper operation = sqlSession.getMapper(UserRoleMapper.class);
			return operation.deleteUserRole(userId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

}
